/*
 * TITLE:RequestBoardQuestion
 * AUTHOR:Manori Thakur
 * PURPOSE: Sends a request to game server to fetch question
 */
package clientrequest;

import java.util.Vector;

import clientresponse.ResponseLocalPlayers;

import android.util.Log;

/** 
 * Send a request to the server for a list of online players 
 * nearby to player and their locations.
 * 'nearby' is defined through a constraint sent to the server.
 * 
 * Some possible uses for this request are displaying other players onscreen or
 * on a minimap, a local chat feature (shout), GPS-enabled communication, etc.
 * @author brian
 */
public class RequestLocalPlayers extends RequestToServer {
	private static final String TAG = RequestLocalPlayers.class.getSimpleName();
	// username -- The server needs the current player's location and a username 
	// is enough info for the server to look up their location up in DB, assuming 
	// it is being updated correctly. (alternative is to send mapcoords directly).
	// location := map and xy-coords on map.
    private String 	username;
    private Short 	constraint,	     // What to return, see constants below.
    			  	screen_width=0,  // Width of display.
    				screen_height=0; // Height of display. 
    
    private final short ONSCREEN=0, ONMAP=1, ONGPS=0;  // constraint enumeration
    
    @Override
    public void send(short requestCode, Vector args) {
    	Log.d(TAG, "Client: sending request to server ...");
    	
    	// args := username, constraint [, screen_width, screen_height |, gps]
    	username = (String) args.get(0);
    	constraint = (Short) args.get(1);
    	if(constraint == ONSCREEN) {
			screen_width = (Short) args.get(2);
			screen_height = (Short) args.get(3);
    	}
    	else if(constraint == ONMAP) {
    		// TODO: Implement
    	}
    	else if (constraint == ONGPS) {
    		// TODO: Implement
    	}
    	
    	// Protocol: size, code, username, constraint, width, height
		short sizeofrequest = (short)(4*4+4*(username.length()));
        super.writeShort(sizeofrequest);
        super.writeShort(requestCode);
        super.writeString(username);
        super.writeShort(constraint);
        super.writeShort(screen_width);
        super.writeShort(screen_height);
        
    }
}